package com.it.travel.controller.admin;

import com.it.travel.common.RequiredPermission;
import com.it.travel.service.admin.AdminCategoryService;
import com.it.travel.vo.Params.PageParams;
import com.it.travel.vo.Params.admin.AdminCategoryParams;
import com.it.travel.vo.Params.admin.AdminCategoryUpdateParams;
import com.it.travel.vo.Params.admin.AdminUserParams;
import com.it.travel.vo.Params.admin.AdminUserUpdateParams;
import com.it.travel.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/admin/category")
@CrossOrigin
public class AdminCategoryController {
    @Resource
    private AdminCategoryService adminCategoryService;

    @GetMapping("")
    public Result<?> getInfoPage(PageParams pageParams) {
//         adminUserService;
        Result<?> result = adminCategoryService.getInfoPage(pageParams);
        return result;
    }

    @RequiredPermission("sys:category:add")

    @PostMapping("")
    public Result<?> save(@RequestBody AdminCategoryParams adminCategoryParams) {
        Result<?> result = adminCategoryService.save(adminCategoryParams);
        return result;
    }
    @RequiredPermission("sys:category:delete")

    @DeleteMapping("/{id}")
    public Result<?> delete(@PathVariable("id") Integer id) {
        Result<?> result = adminCategoryService.delete(id);
        return result;
    }
    @RequiredPermission("sys:category:update")

    @PutMapping("")
    public Result<?> update(@RequestBody AdminCategoryUpdateParams adminCategoryUpdateParams) {
        Result<?> result = adminCategoryService.update(adminCategoryUpdateParams);
        return result;
    }
    @RequiredPermission("sys:category:delete")
    @PostMapping("/deletebatch")
    public Result<?> deletebatch(@RequestBody List<Integer> ids) {
        Result<?> result = adminCategoryService.deletebatch(ids);
        return result;
    }
    @RequiredPermission("sys:category:add")
    @PostMapping("/first")  // 增加一级分类
    public Result<?> saveFirstName(@RequestParam("name") String name) {
        Result<?> result = adminCategoryService.saveFirstName(name);
        return result;
    }

    @GetMapping("/first")  // 获取一级分类
    public Result<?> findFirstName() {
        Result<?> result = adminCategoryService.findFirstName();
        return result;
    }
}
